package com.fqdf.framework.android.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.BaseAdapter;


import com.fqdf.framework.android.util.CheckLogicUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 张枭
 *         date 2017/4/6
 * @version V1.0
 */
public abstract class BaseMyAdapter<T> extends BaseAdapter {


    private List<T> originList;

    private Context mContext;

    private LayoutInflater layoutInflater;

    public BaseMyAdapter(Context context) {
        this(context, null);
    }

    public BaseMyAdapter(Context context, List<T> data) {
        mContext = context;
        layoutInflater = LayoutInflater.from(mContext);
        if (CheckLogicUtil.isEmpty(data)) {
            originList = new ArrayList<>();
        } else {
            originList = data;
        }
    }

    public void setList(List<T> data) {
        if (originList != null) {
            originList = data;
        }
    }

    public void addList(List<T> data) {
        if (originList != null) {
            originList.addAll(data);
        }
    }

    public void clearList() {
        originList.clear();
    }

    @Override
    public int getCount() {
        return originList.size();
    }

    public T getItem(int position) {
        return originList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    public Context getContext() {
        return mContext;
    }

    public List<T> getOriginList() {
        return originList;
    }

    public LayoutInflater getLayoutInflater() {
        return layoutInflater;
    }
}
